<template>
  <div id="total-mileage">
    <div id="total-mileage-title">
      <div class="total-mileage-title">
        <img src="static/img/yellow-con.png" class="total-mileage-img1">
        <img src="static/img/yellow-con.png" class="total-mileage-img2">
        <img src="static/img/yellow-con.png" class="total-mileage-img3">
        <img src="static/img/yellow-con.png" class="total-mileage-img4">
        <img src="static/img/yellow-con.png" class="total-mileage-img5">
        <img src="static/img/yellow-con.png" class="total-mileage-img6">
        <img src="static/img/yellow-con.png" class="total-mileage-img7">
        <img src="static/img/yellow-con.png" class="total-mileage-img8">
        <img src="static/img/blue-con.png" class="total-mileage-img9">
        <img src="static/img/blue-con.png" class="total-mileage-img10">
        <img src="static/img/blue-con.png" class="total-mileage-img11">
        <img src="static/img/blue-con.png" class="total-mileage-img12">
        <span>30天内全国车辆总里程数（km）</span>
      </div>
    </div>
    <div id="total-mileage-num">
      {{allnum}}
    </div>
  </div>
</template>

<script>
  export default {
    name: 'total-mileage',
    data() {
      return {
        allnum: 234567890,
        timeList : 1513645200000
      }
    },
    mounted() {
      this.drawMileage();
      this.changeTimeList();
    },
    methods: {
      drawMileage: function () {
        let that = this;
        const total_sumdistance = [];
        $.ajax({
          type : 'get',
          async :true,
          url: 'http://203.81.245.37:2420/platformservice/left/' +that.timeList ,
          data : {},
          dataType: 'json',
          success : function (result) {
            if (result) {
              let total_sumdistance = result.sumdistance;
              for (var i=0;i<total_sumdistance.length;i++) {
                total_sumdistance.push(total_sumdistance[i])
              }
//              console.log(99999999);
//              console.log(total_sumdistance);
//              console.log(typeof total_sumdistance)
              const _allnum = total_sumdistance.toString();
//              console.log(_allnum);
              const _allnum1 = _allnum.substr(0,3);
              const _allnum2 = _allnum.substr(3,3);
              const _allnum3 = _allnum.substr(6,3);
              const _allnum4 = _allnum1 + "," +_allnum2+ "," +_allnum3;
//              console.log(_allnum4);
              that.allnum = _allnum4;
            }
          }
        })
      },
      changeTimeList : function () {
        var timeList = [1514422800000,1514336400000,1514250000000,1514163600000,1514077200000,1513990800000,1513904400000,1513818000000,1513731600000,1513645200000];
        var j = 0;
        setInterval( () => {
          this.timeList = timeList[j];
//          console.log(timeList[j]);
          if (j < timeList.length-1){
            j+=1;
          }else {
            j = 0;
          }
          this.drawMileage();
        },60000)
      }
    }
//    created: function () {
//      var url = "http://203.81.245.37:2420/platformservice/left/1513645200000";
//
//      this.$http.get(url).then( (allnum) => {
//        var json = allnum.body.sumdistance;
//        console.log(allnum.body.sumdistance);
//        this.allnum = json;
//      },function (response) {
//        console.info(response);
//      })
//    }
  }
</script>

<style scoped>
  #total-mileage {
    height: 100px;
    width: 440px;
    position: relative;
  }
  #total-mileage-title {
    height: 40px;
    width: 438px;
    background: rgba(7, 34, 31, 0.8);
    border-width: 1px;
    border-style: solid;
    border-color: rgba(32, 221, 201, 0.8);
    border-image: initial;
  }
  .total-mileage-title {
    height: 30px;
    width: 428px;
    position: absolute;
    top: 6px;
    left: 6px;
    font-family: MicrosoftYaHeiUI;
    text-align: left;
    text-indent: 4px;
    font-size: 18px;
    line-height: 30px;
    color: rgb(239, 187, 66);
    letter-spacing: -0.45px;
    background: rgba(0, 158, 158, 0.2);
  }
  #total-mileage-num {
    height: 57px;
    width: 438px;
    background: rgba(7,34,31,0.80);
    border: 1px solid rgba(32,221,201,0.80);
    position: absolute;
    top: 40px;
    /*left: 1px;*/
    font-family: MicrosoftYaHeiUI-Bold;
    font-size: 48px;
    color: #FFFFFF;
    letter-spacing: 10px;
    line-height: 58px;
    text-align:center;
  }
  .total-mileage-img1 {
    position: absolute;
    top: -7px;
    left: -7px;
    z-index: 3;
  }
  .total-mileage-img2 {
    position: absolute;
    top: -7px;
    left: 429px;
    transform: rotate(90deg);
    z-index: 3;
  }
  .total-mileage-img3 {
    position: absolute;
    top: 30px;
    left: 429px;
    transform: rotate(180deg);
    z-index: 3;
  }
  .total-mileage-img4 {
    position: absolute;
    top: 30px;
    left: -7px;
    transform: rotate(270deg);
    z-index: 3;
  }
  .total-mileage-img5 {
    position: absolute;
    top: 33px;
    left: -7px;
    z-index: 3;
  }
  .total-mileage-img6 {
    position: absolute;
    top: 33px;
    left: 429px;
    transform: rotate(90deg);
    z-index: 3;
  }
  .total-mileage-img7 {
    position: absolute;
    top: 88px;
    left: 429px;
    transform: rotate(180deg);
    z-index: 3;
  }
  .total-mileage-img8 {
    position: absolute;
    top: 88px;
    left: -7px;
    transform: rotate(270deg);
    z-index: 3;
  }
  .total-mileage-img9 {
    position: absolute;
    top: -1px;
    left: -1px;
    z-index: 3;
  }
  .total-mileage-img10 {
    position: absolute;
    top: -1px;
    left: 425px;
    transform: rotate(90deg);
    z-index: 3;
  }
  .total-mileage-img11 {
    position: absolute;
    top: 27px;
    left: 425px;
    transform: rotate(180deg);
    z-index: 3;
  }
  .total-mileage-img12 {
    position: absolute;
    top: 27px;
    left: -1px;
    transform: rotate(270deg);
    z-index: 3;
  }
</style>
